<?php
/*
 * @author banban
 * @datetime 2019-3-9 11:04:06
 * @copyright 板板<249366615@qq.com>
 * @filename Order
 */
namespace App\Model\BbcModel;

use App\Model\BaseModel\BaseBbcModel;

class Order extends BaseBbcModel {

    public $table = 'ly_order';

    /**
     * 获取用户订单数量
     * @param $mid
     * @param $mnid
     * @param $mnsid
     * @param $cid
     * @return array|int[]
     * @author: hj
     */
    public static function getMemberOrderNum($mid, $mnid, $mnsid, $cid) {
        $orderNumMap = ['pay' => 0, 'sent' => 0, 'clear' => 0, 'get' => 0, 'comment' => 0];
        if (!$mid) {
            return $orderNumMap;
        }
        if ($mnid == 0) {
            $distribute_id = Member::where('mid', $mid)->value('distribute_id');
            if ($distribute_id) {
                $mnsid = Mnuser::where('mid', $distribute_id)->where('status', 1)->where('mnid', 0)->value('id');
            }
        }
        $order = self::where('mid', $mid)->where('mnid', $mnid)->where('mn_sid', $mnsid)
            ->where('cid', $cid)->whereIn('status', [10, 20, 21, 30, 50])->select(['status', 'is_comment'])->get();
        if ($order->isEmpty()) {
            return $orderNumMap;
        }
        return [
            'pay'     => $order->where('status', 10)->count(),
            'sent'    => $order->where('status', 20)->count(),
            'clear'   => $order->where('status', 21)->count(),
            'get'     => $order->where('status', 30)->count(),
            'comment' => $order->where('status', 50)->whereStrict('is_comment', 0)->count()
        ];
    }
}
